﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
using System.IO.IsolatedStorage;


namespace PreferredZhiTu.Views
{
    public partial class Search : PhoneApplicationPage
    {
       // string str_ItemContent;
        public Search()
        {
            InitializeComponent();
        }

        private void listBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {//选择宾馆
            //NavigationService.Navigate(new Uri("/Views/JingDian.xaml?selectItem=" + listBox2.SelectedIndex, UriKind.Relative));
        }

        public string city;
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {//加载当前城市
            pivot1.Title = "当期城市：";
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                IsolatedStorageFileStream fs = file.OpenFile("city.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                StreamReader sr = new StreamReader(fs);
                city = sr.ReadToEnd();
                sr.Close();
                fs.Close();
            }
           
            pivot1.Title += city;
        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {//获取选择的景点和宾馆
            //    using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            //    {
            //        IsolatedStorageFileStream fs = file.OpenFile("Jingdian", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            //        StreamWriter sw = new StreamWriter(fs);
            //        sw.WriteLine(Name);//将选择查看的景点名称写入文件
            //        sw.Close();
            //        fs.Close();
            //    }
            if (listBox1 .SelectedItems .Count !=0&&listBox1 .SelectedItems .Count !=1&&listBox2 .SelectedItems .Count ==1)
            {
                NavigationService.Navigate(new Uri("/Views/XingCheng.xaml", UriKind.Relative));
            }
            else
            {
                MessageBox.Show("请选择两个以上景点和一个宾馆");
            }
            
          
        }
       
        public string binguan;
        private void listBox2_DoubleTap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            ListBox lb = (ListBox)listBox2;
            ListBoxItem item = (ListBoxItem)this.listBox2.SelectedItem;
            if (null != item)
            {
                binguan = item.Content.ToString();
                //MessageBox.Show(binguan);
            }           
            NavigationService.Navigate(new Uri("/Views/Hotel.xaml?selectItem=" + listBox2.SelectedIndex, UriKind.Relative));
        }

        private void listBox1_DoubleTap(object sender, System.Windows.Input.GestureEventArgs e)
        {//获取选中的景点名称
            NavigationService.Navigate(new Uri("/Views/JingDian.xaml?selectItem=" + listBox1.SelectedItems, UriKind.Relative));
        }

        

    }
}